% De-specle Filter
% ================
% This example performs very simple binarization and therefore
% despecle algorith can help to improve the data input. Suggested
% algorithm removes the 1x1 specles, both white and black. The
% logical function is suggested as follows:
%
% Can filter the signals:
%    _
% __| |__   ->  _______  (removing white specle in black bar)
% __   __       _______
%   |_|     ->           (removing black specle in white bar)
%    _   __          ___
% __| |_|    ->  ___|    (removing the noise at the edge black-white)
% __   _         ___
%   |_| |__  ->     |___ (removing the noise at the edge white-black)
%
% Binarizer is standard global threasholder. Takes threashold as input.
% Binarized image is filtered for specles 1x1 pixel, both colors.
% Filter uses logical function:
%      _           _
%   f=zxy + zx + xyz
%
% has been determined for table:
%
%    px-1 | px  | px+1 | foo
%     (x) | (y) |  (z) | (f)
%   ------+-----+------+------
%     1   |  1  |  0   |  1
%     0   |  0  |  1   |  0
%     1   |  0  |  1   |  1
%     0   |  1  |  0   |  0
%     0   |  1  |  1   |  1
%     1   |  0  |  0   |  0
%     1   |  1  |  1   |  1
%     0   |  0  |  0   |  0
%
%
function l = despecle(x,y,z)
	t1 = z*not(x)*y;
	t2 = z*x;
	t3 = x*y*not(z);
	l = logical(t1+t2+t3);
endfunction
